package com.kly.cashmall.module.home.home_tab;

import com.kly.cashmall.R;
import com.kly.cashmall.module.mine.AccountFragment;
import com.kly.cashmall.module.home.home_tab.tab_view.FragmentPackage;
import com.kly.cashmall.module.home.home_tab.tab_view.MenuTabInfo;
import com.kly.cashmall.module.index.IndexFragment;
import com.kly.cashmall.module.order.LoanTypeFragment;
import com.kly.cashmall.module.products.ProductsFragment;

import java.util.Arrays;
import java.util.List;

/**
 * @author
 * @date 2018/1/3
 */
public class FragmentClassMap {

  public static List<FragmentPackage<MenuTabInfo>> findDefaultFragments() {
    return Arrays.asList(buildFragmentPackage(new MenuTabInfo("Home", MenuTabInfo.TAG_HOME,0)),
            buildFragmentPackage(new MenuTabInfo("Orders", MenuTabInfo.TAG_LOAN_ORDERS,1)),
            buildFragmentPackage(new MenuTabInfo("Account", MenuTabInfo.TAG_MINE_CENTER,1)));
  }

  public static FragmentPackage<MenuTabInfo> buildFragmentPackage(MenuTabInfo menuTabInfo) {
    if (menuTabInfo == null || menuTabInfo.jumpValue == null) {
      return null;
    }

    if (menuTabInfo.isMatch(MenuTabInfo.TAG_HOME)) {
      menuTabInfo.iconResource = R.drawable.selector_loan_tab;
      return new FragmentPackage<>(menuTabInfo, IndexFragment.class, "");
    }

    if (menuTabInfo.isMatch(MenuTabInfo.TAG_LOAN_PRODUCTS)) {
      menuTabInfo.iconResource = R.drawable.selector_loan_tab;
      return new FragmentPackage<>(menuTabInfo, ProductsFragment.class, "");
    }

    if (menuTabInfo.isMatch(MenuTabInfo.TAG_LOAN_ORDERS)) {
      menuTabInfo.iconResource = R.drawable.selector_loan_tab;
      return new FragmentPackage<>(menuTabInfo, LoanTypeFragment.class, "");
    }

    if (menuTabInfo.isMatch(MenuTabInfo.TAG_MINE_CENTER)) {
      menuTabInfo.iconResource = R.drawable.selector_loan_tab;
      return new FragmentPackage<>(menuTabInfo, AccountFragment.class, "");
    }

    return null;
  }

}
